#! /bin/bash

liveuser=${1:-eeedora}

mypath=`echo $0 | sed -e 's|/[^/]*$||'`

# This must be done as root
yumlist=''

function ask {
 echo -n $1
 read ans
 response=false
 if [ "${ans:0:1}" == "y" ] || [ "${ans:0:1}" == "Y" ] ; then
  response=true
 fi 
}  

ask "Select OpenOffice Components ? [yes/NO]"
if ${response}; then
 ask "Install OpenOffice Calc ? [yes/NO]"
 if ${response}; then
  yumlist="${yumlist} openoffice.org-calc"
 fi
 ask "Install OpenOffice Writer ? [yes/NO]"
 if ${response}; then
  yumlist="${yumlist} openoffice.org-writer"
 fi
fi

ask "Select productivity tools ? [yes/NO]"
if ${response}; then
 ask "Install Password Manager 'KeePass' ? [yes/NO]"
 if ${response}; then
  yumlist="${yumlist} keepassx"
 fi

 ask "Install Personal Information Manager 'osmo' ? [yes/NO]"
 if ${response}; then
  osmo_fix=yes
  yumlist="${yumlist} osmo"
 fi

 ask "Install Desktop Wiki editor 'Zim' ? [yes/NO]"
 if ${response}; then
  yumlist="${yumlist} Zim"
 fi
fi

ask "Install Samba	 for Windows connectivity ? [yes/NO]"
if ${response}; then
 yumlist="${yumlist} samba-client"
fi

ask "Install IcedTea Java plugin for Firefox ? [yes/NO]"
if ${response}; then
 yumlist="${yumlist} java-1.7.0-icedtea-plugin"
fi

ask "Install Flash plugin for Firefox from Adobe ? [yes/NO]"
if ${response}; then
 flash=yes
fi

ask "Install PDF viewer 'evince' ? [yes/NO]"
if ${response}; then
 evince_fix=yes
 yumlist="${yumlist} evince"
fi

ask "Install backup client 'unison' ? [yes/NO]"
if ${response}; then
 unison_fix=yes
 yumlist="${yumlist} unison227"
fi

ask "Select a Media Player ? [yes/NO]"
if ${response}; then
 ask "Install Media Player 'vlc' ? [yes/NO]"
 if ${response}; then
  # May need to fix this up for pulseaudio - do this below
  vlc_fix=yes
  yumlist="${yumlist} vlc"
 fi
 ask "Install Media Player 'gxine' ? [yes/NO]"
 if ${response}; then
  # May need to fix this up for pulseaudio - do this below
  gxine_fix=yes
  yumlist="${yumlist} gxine"
 fi
fi

ask "Select Games ? [yes/NO]"
if ${response}; then
 ask "Install OpenArena (FPS - Quake III engine) ? [yes/NO]"
 if ${response}; then
  yumlist="${yumlist} openarena"
 fi
 ask "Install Tremulous (FPS/Strategy - Quake III engine) ? [yes/NO]"
 if ${response}; then
  yumlist="${yumlist} tremulous"
 fi
 ask "Install Quake3 (needs game CD too) ? [yes/NO]"
 if ${response}; then
  yumlist="${yumlist} quake3"
 fi
fi

echo ''

affirm=''
ask "Install fully automatically ? [yes/NO]"
if ${response}; then
 affirm="-y"
fi

echo ''

if [ "is${flash}" = "isyes" ]; then
 rpm -ivh "http://fpdownload.macromedia.com/get/flashplayer/current/flash-plugin-9.0.115.0-release.i386.rpm"
fi

if ! [ "empty${yumlist}" = "empty" ]; then
 echo $"yumlist = '${yumlist}'"
 yum install ${affirm} ${yumlist}
fi

# Now do various clean-ups - to fix pulseaudio, for instance
if [ "is${vlc_fix}" = "isyes" ]; then
 echo "pulseaudio already Ok for vlc"
fi

if [ "is${gxine_fix}" = "isyes" ]; then
 echo "pulseaudio already Ok for gxine - barring the odd glitch"
fi

if [ "is${evince_fix}" = "isyes" ]; then
 echo "TODO : Add menu entry for evince"
fi

if [ "is${osmo_fix}" = "isyes" ]; then
 echo "Setting up default config for osmo"
 tar -xzf ${mypath}/dot-osmo.tar.gz -C /home/${liveuser}/
 chown -R ${liveuser}:${liveuser} /home/${liveuser}/.osmo
fi

